from django.db import models

# Create your models here.
# Create your models here.
class cInformation(models.Model):
    """ complay\translate\supermaket  basic infomation"""
    # yong hu lie bie
    userCategory = models.CharField(verbose_name = "机构分类", max_length=20, null=False)
    # bian ma
    userCode = models.IntegerField(null=False,verbose_name = '机构代码')
    # gongsi \yunshu \
    userName = models.CharField(max_length=20, null=False, verbose_name = '机构名称')

    userVehileNum = models.CharField(max_length=20,blank= True,null=True, verbose_name = '车辆号码')
    # faren
    userLawer = models.CharField(max_length=20, null=False, verbose_name = '法人')
    # zizi
    userQualification = models.CharField(max_length=20,null=True,verbose_name = '机构资质')
    # zhuce dizhi
    userAddr = models.CharField(max_length=60, null=False, verbose_name = '机构地址')
    # dainhua
    userTel = models.BigIntegerField(null=False, verbose_name = '用户电话')
    # youjian
    userEmail = models.CharField(max_length=20, null=False,verbose_name = '用户邮箱')

    userManager = models.IntegerField(verbose_name='所受监管',default=0)
    # miam
    userPasswd = models.CharField(max_length=20, null=False, verbose_name= '用户密码')
    # sanchujian
    isDel = models.BooleanField(default=False,verbose_name= '删除标记')

    def __str__(self):
        # return self.user_category,self.user_name,self.user_lawer
        return str(self.userName) + ":" + str(self.userCode)
    class Meta:
        verbose_name = '信息汇总'
        verbose_name_plural = '信息汇总'



class ProductDetail(models.Model):
    """product detail table"""
    # shang ping ming cheng
    proName = models.CharField(max_length=20, verbose_name = '产品名称')
    proCode = models.IntegerField(null=False, verbose_name = '产品代码')
    proLawer = models.CharField(max_length=20,  verbose_name = '生产法人')
    manEnterprise = models.ForeignKey('cInformation',verbose_name = '生产厂商')
    transer = models.CharField(max_length=20, verbose_name='承运人')
    transerSensor = models.IntegerField(verbose_name='承运传感器编号')
    superer = models.CharField(max_length=20, verbose_name='商超代售',null=True,blank=True)
    supererSnesor = models.IntegerField(verbose_name='商超传感器编号', null=True, blank=True)
    manAddr = models.CharField(max_length=20, verbose_name = '工厂地址')
    manDate = models.DateField(verbose_name = '生产日期')
    expDate = models.IntegerField(verbose_name = '保质期')
    certificateText = models.CharField(max_length=20, verbose_name = '检疫检验')
    examiner = models.CharField(max_length=20, verbose_name = '检验人')
    evaluate = models.IntegerField(null= False, blank=False ,default=0,verbose_name='安全评估')
    isDel = models.BooleanField(default=False,verbose_name= '删除标记')


    def __str__(self):
        # return self.user_category,self.user_name,self.user_lawer
        return self.proName
    class Meta:
        verbose_name = '产品详细'
        verbose_name_plural = '产品详细'

    def toJSON(self):
        fields = []
        for field in self._meta.fields:
            fields.append(field.name)

        d = {}
        for attr in fields:
            d[attr] = getattr(self, attr)

        import json
        return json.dumps(d)

class HardDetail(models.Model):
    """2"""
    hardCode = models.IntegerField(null=False,verbose_name = '硬件代码')
    hardLawer = models.ForeignKey('cInformation',verbose_name = '硬件所属')
    boardDetail = models.CharField(max_length=40,verbose_name = '主板详细')
    curState = models.BooleanField(default=True,verbose_name = '当前状态')
    fixDetail = models.TextField(blank= True,null=True,verbose_name = '维修详细')
    fixData = models.DateField(blank= True,null=True,verbose_name = '最近维修')
    netState = models.BooleanField(default=True,verbose_name = '网络状态')
    isDel = models.BooleanField(default=False,verbose_name= '删除标记')


    def __str__(self):
        return str(self.hardCode)
    class Meta:
        verbose_name = "硬件详细"
        verbose_name_plural = "硬件详细"


class BasicSensor(models.Model):
    """sensor basic data"""
    sensorName = models.CharField(max_length=20,null=False,verbose_name = '传感器名称')
    sensorHard = models.ForeignKey('HardDetail',verbose_name = '所属硬件')
    sensorState = models.BooleanField(default=True,verbose_name = '传感器状态')
    sensorDate = models.DateTimeField(auto_now=True,verbose_name= '记录日期')
    sensorData = models.DecimalField(max_digits=5, decimal_places=2,verbose_name = '记录数据')
    isDel = models.BooleanField(default=False,verbose_name= '删除标记')

    def __str__(self):
        return str(self.sensorHard) +':'+ str(self.sensorName)
    class Meta:
        verbose_name = '基础传感器'
        verbose_name_plural = '基础传感器'


class Advise(models.Model):
    """1"""
    adName = models.CharField(max_length=20,verbose_name = '投诉人名字')
    adDoods = models.ForeignKey('ProductDetail',verbose_name ='投诉商品')
    adTel = models.BigIntegerField(null=False,verbose_name = '投诉人电话')
    adMail = models.CharField(max_length=40,verbose_name = '投诉人邮件')
    adIdCard = models.CharField(max_length=20,verbose_name = '投诉人身份证')
    adDate = models.DateField(auto_now=True,verbose_name = '投诉日期')
    adConsumerText = models.TextField(verbose_name = '投诉内容')
    adSupermaketText = models.TextField(verbose_name = '商超意见',blank= True,null=True)
    adMangerText = models.TextField(verbose_name = '监督意见',blank= True,null=True)
    adDealSupermarket = models.DateField(verbose_name = '商超处理',blank= True,null=True)
    adDealManger = models.DateField(verbose_name= '监督处理',blank= True,null=True)
    adReturn = models.BooleanField(default=False, verbose_name='驳回') # TODO 9
    adDealFinish = models.DateField(verbose_name = '完成日期',blank= True,null=True)
    isDel = models.BooleanField(default=False,verbose_name= '删除标记')

    def __str__(self):
        return self.adName
    class Meta:
        verbose_name = '投诉建议'
        verbose_name_plural = '投诉建议'


class PictureM(models.Model):
    """media file manager"""
    pic = models.ImageField(upload_to='messageDisplay/',verbose_name = '图片保存路径')

    def __str__(self):
        return str(self.pic)
    class Meta:
        verbose_name = '图片管理'
        verbose_name_plural = '图片管理'

